package hgz.stu.review.mock;

import org.junit.Test;
import org.junit.runner.RunWith;

import mockit.Expectations;
import mockit.Mocked;
import mockit.Verifications;
import mockit.integration.junit4.JMockit;

@RunWith(JMockit.class)
public class TestMockSample {
	//被修饰的对象将会被Mock，对应的类和实例都会受影响
	@Mocked
	SimpleTool simpleTool;

	@Test
	public void testExpectation() {

	    //未mock函数返回null
	    new Expectations() {
	        {
	            simpleTool.fun1(anyString);
	            result = "MOCK";
	        }
	    };

	    System.out.println(simpleTool.fun1("param"));
	    System.out.println(simpleTool.fun3("param"));
	    System.out.println(new UseSimpleTool().fun1("param"));

	    new Verifications() {
	       {
	           simpleTool.fun1(anyString);
	           times = 2;
	       }
	    };
	}
}
